const verifyUpdateAC = async (ctx, next) => {
  ctx.keyList = ["id", "content"];
  await next();
};

const verifyRemoveAC = async (ctx, next) => {
  ctx.keyList = ["id"];
  await next();
};

const verifyAddAC = async (ctx, next) => {
  ctx.keyList = ["content"];
  await next();
};

const verifyAddA = async (ctx, next) => {
  ctx.keyList = [
    "title",
    "author",
    "content",
    "keywords",
    "desc",
    "category_id",
  ];
  await next();
};

const verifyUpdateA = async (ctx, next) => {
  ctx.keyList = [
    "id",
    "title",
    "author",
    "content",
    "keywords",
    "desc",
    "category_id",
  ];
  await next();
};

const verifyGetManagerList = async (ctx, next) => {
  ctx.keyList = [
    "status",
    "category_id",
    "page",
    "pageSize",
    "keywords",
  ];
  await next();
};

const verifyGetClientList = async (ctx, next) => {
  ctx.keyList = [
    "category_id",
    "page",
    "pageSize",
    "keywords",
  ];
  await next();
};

const verifyIsEmpty = async (ctx, next) => {
  const paramsList = ctx.request.body;
  const keyList = ctx.keyList;
  let requestKeys = Object.keys(paramsList);
  let emptyArr = [];
  for (let item of keyList) {
    let ele = requestKeys.find((ele) => ele == item);
    if (!ele) {
      emptyArr.push(item);
    }

    // if(ele&&String(paramsList[ele].trim()).length==0){
    //   emptyArr.push(item);
    // }
  }
  if (emptyArr.length > 0) {
    let message = emptyArr.join();
    ctx.body = {
      code: 400,
      msg: `${message}不得为空`,
    };
  } else {
    await next();
  }
};

module.exports = {
  verifyIsEmpty,
  verifyUpdateAC,
  verifyAddAC,
  verifyRemoveAC,
  verifyAddA,
  verifyUpdateA,
  verifyGetManagerList,
  verifyGetClientList
};
